package com.jiuzhou.guanwang.jzcp.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;

import com.jiuzhou.guanwang.jzcp.R;
import com.jiuzhou.guanwang.jzcp.base.BaseRecyclerAdapter;
import com.jiuzhou.guanwang.jzcp.base.BaseRecyclerHolder;
import com.jiuzhou.guanwang.jzcp.bean.HomeCPBean;
import com.jiuzhou.guanwang.jzcp.utils.TimeUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @ explain:
 * @ author：xujun on 2016/10/18 16:42
 * @ email：gdutxiaoxu@163.com
 */
public class AwardItemAdapter extends BaseRecyclerAdapter<HomeCPBean> {
    private String[] support_lotterys = {"ssq", "dlt", "fc3d", "pl3", "pl5", "qxc", "qlc", "js11x5", "jsk3"};
    private Context mContex;
    public AwardItemAdapter(Context context, List<HomeCPBean> datas) {
        super(context, R.layout.item_opencode, datas);
        mContex = context;
    }

    @Override
    public void convert(BaseRecyclerHolder holder, HomeCPBean item, int position) {
        holder.setText(R.id.tv_name,item.getName());
        holder.setText(R.id.tv_desc,"第"+item.getExpect()+"期"+"  "+ TimeUtil.changeToYYMMDD(item.getTime()));
        switch (item.getCode()){
            case "ssq":
              holder.setImageResource(R.id.icon, R.drawable.ic_ssq3);
                break;
            case "dlt":
                holder.setImageResource(R.id.icon, R.drawable.ic_dlt3);
                break;
            case "fc3d":
                holder.setImageResource(R.id.icon, R.drawable.ic_3d2);
                break;
            case "pl3":
                holder.setImageResource(R.id.icon, R.drawable.ic_pls3);
                break;
            case "pl5":
                holder.setImageResource(R.id.icon, R.drawable.ic_plw3);
                break;
            case "qxc":
                holder.setImageResource(R.id.icon, R.drawable.ic_qxc3);
                break;
            case "qlc":
                holder.setImageResource(R.id.icon, R.drawable.ic_qlc3);
                break;
            case "js11x5":
                holder.setImageResource(R.id.icon, R.drawable.ic_11x5);
                break;
            case "jsk3":
                holder.setImageResource(R.id.icon, R.drawable.ic_k3);
                break;
        }
        if (!TextUtils.isEmpty(item.getOpenCode())) {
            List<String> data = new ArrayList();
            if (item.getOpenCode().contains("+")) {
                String[] split = item.getOpenCode().split("\\+");
                for (int i = 0; i < split.length; i++) {
                    if (i == 0) {
                        if (split[i].length() > 0) {
                            for (String s : split[i].split(",")) {
                                data.add(s);
                            }
                        }
                    } else if (split[i].length() > 0) {
                        for (String s2 : split[i].split(",")) {
                            data.add(s2 + "#");
                        }
                    }
                }
            } else if (item.getOpenCode().contains(",")) {
                for (String s22 : item.getOpenCode().split(",")) {
                    data.add(s22);
                }
            }
            CodeAdapter codeAdapter = new CodeAdapter(this.mContex,data);
            LinearLayoutManager layoutManager = new LinearLayoutManager(this.mContex);
            layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
            ((RecyclerView) holder.getView(R.id.rv_code)).setFocusable(false);
            ((RecyclerView) holder.getView(R.id.rv_code)).setLayoutManager(layoutManager);
            ((RecyclerView) holder.getView(R.id.rv_code)).setAdapter(codeAdapter);
        }

    }

}
